< previous page page_346 next page >

Page 346
Of course using the error numbers themselves is not a very good practice. You should probably declare global constants to define each error that you may encounter.
Fix and Resume
If the user is getting a divide-by-zero error, you can easily remedy this via some simple coding on your part. All you have to do is detect that a divide-by-zero error has occurred by checking the Err.Number property to see if its number 11. If it is, you can inform the user of the problem and prompt the user for a new divisor using the InputBox() function. Heres how:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdFixResume_Click()
   On Error GoTo Error_EH

   txtResult = CInt(txtDividend) / CInt(txtDivisor)

   Exit Sub

Error_EH:
   If Err.Number = 11 Then
      MsgBox "A Divide By Zero Error Has Occurred, " & _
             "Please enter a new divisor"
      txtDivisor = InputBox("Enter a Divisor", "Divisor")
      Resume
   Else
      MsgBox Err.Description
   End If
   Err.Clear

   Exit Sub
End Sub
After the user inputs the new divisor, you can then perform a Resume statement to retry the operation one more time.
Errors in the Call Stack
Lets take a look at what happens when error handling is only used in some but not all procedures in a program. When clicked, the CallStack command button on the FileLen.frm form in the sample project calls three procedures. The first procedure

 
< previous page page_346 next page >

If you like this book, buy it!